<%@ page import="org.springframework.web.context.request.SessionScope" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/layui-v2.9.14/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/xm-select.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/crypto-js.js"></script>
    <title></title>
</head>
<body>

<form class="layui-form" action="">

    <div class="layui-form-item">
        <input type="hidden" name="userId"  value="${userId}" readonly autocomplete="off" class="layui-input">

        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username"  value="${username}" readonly autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">

            <label class="layui-form-label">充值金额</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="number" name="money" placeholder="" autocomplete="off" class="layui-input" min="1" step="10" lay-affix="number">
            </div>


    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即充值</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 提交事件
        form.on('submit(demo1)', function(data){
            var field = data.field; // 获取表单字段值
            $.post("/user/recharge.do", field, function (res) {
                if(res.code==0){//充值成功
                    layer.msg(res.msg,{time:2000},function (res){
                        location.href="/user/tolist.do"
                    })
                }else{
                    layer.msg(res.msg,{time:2000},function (res){

                    })
                }
            })
            return false; // 阻止默认 form 跳转
        });

    });
</script>

</body>
</html>